/**
 * @copyright Copyright (c) 2025 CSG Digital Grid Technology (Guangdong) Co., Ltd.
 * @author Chen Yongjie
 */
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <CUnit/Basic.h>

#include <test_string2json.h>
#include "test_app_action.h"

int main() {
    // 初始化 CUnit 测试套件
    if (CUE_SUCCESS != CU_initialize_registry()) {
        return CU_get_error();
    }
    CU_pSuite pSuite1 = CU_add_suite("suite_1", NULL, NULL);
    CU_pSuite pSuite2 = CU_add_suite("suite_2", NULL, NULL);
    if (NULL == pSuite1) {
        CU_cleanup_registry();
        return CU_get_error();
    }
    if (NULL == pSuite2) {
        CU_cleanup_registry();
        return CU_get_error();
    }

    // 添加测试用例到套件1
    if (NULL == CU_add_test(pSuite1, "测试日志记录函数", test_log_record)) {
        CU_cleanup_registry();
        return CU_get_error();
    }
    if (NULL == CU_add_test(pSuite1, "测试控制应用消息处理函数", test_control_action_message_dispose)) {
        CU_cleanup_registry();
        return CU_get_error();
    }
    if (NULL == CU_add_test(pSuite1, "测试应用名称检查和路径转换函数", test_check_appname_and_get_absolute_path)) {
        CU_cleanup_registry();
        return CU_get_error();
    }
    if (NULL == CU_add_test(pSuite1, "测试应用列表信息处理函数", test_app_list_info_dispose)) {
        CU_cleanup_registry();
        return CU_get_error();
    }
    if (NULL == CU_add_test(pSuite1, "测试读取应用配置文件JSON值函数", test_read_appprofile_json_values)) {
        CU_cleanup_registry();
        return CU_get_error();
    }
    // 在现有的测试用例后添加
    if (NULL == CU_add_test(pSuite1, "测试打开应用配置文件函数", test_open_appprofile_ctl)) {
        CU_cleanup_registry();
        return CU_get_error();
    }

    // 添加APN模块测试用例
    if (NULL == CU_add_test(pSuite1, "测试APN添加功能", test_wwan_apn_add)) {
        CU_cleanup_registry();
        return CU_get_error();
    }
    
    if (NULL == CU_add_test(pSuite1, "测试APN显示功能", test_wwan_apn_show)) {
        CU_cleanup_registry();
        return CU_get_error();
    }
    
    if (NULL == CU_add_test(pSuite1, "测试按索引删除APN功能", test_wwan_apn_delete_one)) {
        CU_cleanup_registry();
        return CU_get_error();
    }
    
    if (NULL == CU_add_test(pSuite1, "测试按运营商删除APN功能", test_wwan_apn_delete_carrier)) {
        CU_cleanup_registry();
        return CU_get_error();
    }

    // 运行测试用例
//    CU_basic_set_mode(CU_BRM_VERBOSE);
//    CU_basic_run_tests();

    // 设置自动化模式的输出文件名
    CU_set_output_filename("CUnit");

    // 运行自动化测试
    CU_automated_run_tests();

    CU_cleanup_registry();
    return CU_get_error();
}